<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<link rel="stylesheet" href="assets/mui/css/mui.min.css">
	<!-- <link rel="stylesheet" href="css/form.css"> -->
	<link rel="stylesheet" href="css/base.css">
	<script src="assets/zepto/zepto.min.js"></script>
	<script src="assets/artTemplate/template-native.js"></script>
	<script src="assets/mui/js/mui.min.js"></script>
	<!-- <script src="js/login.js"></script> -->
	<!-- <script src="js/public.js"></script> -->
	<style>
		.mui-content,
        .mui-content input{
            font-size: 14px;
        }
	</style>
</head>
<body>
	<header class="mui-bar mui-bar-nav my-header">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		<h1 class="mui-title">用户登录</h1>
	</header>
	<nav class="mui-bar mui-bar-tab my-footer">
		<a class="mui-tab-item" href="home.html">
			<span class="mui-icon mui-icon-home"></span>
			<span class="mui-tab-label">首页</span>
		</a>
		<a class="mui-tab-item" href="catagory.html">
			<span class="mui-icon mui-icon-bars"></span>
			<span class="mui-tab-label">分类</span>
		</a>
		<a class="mui-tab-item" href="cart.html">
			<span class="mui-icon iconfont icon-daohanggouwuche"></span>
			<span class="mui-tab-label">购物车</span>
		</a>
		<a class="mui-tab-item" href="user.html">
			<span class="mui-icon mui-icon-person"></span>
			<span class="mui-tab-label">会员中心</span>
		</a>
	</nav>
	<div class="mui-content">
		<form class="mui-input-group">
		    <div class="mui-input-row">
		        <label>用户名</label>
		    	<input type="text" class="mui-input-clear" placeholder="请输入用户名" name="username" id="username">
		    </div>
		    <div class="mui-input-row">
		        <label>密码</label>
		        <input type="password" class="mui-input-password" placeholder="请输入密码" name="password" id="password">
		    </div>
		    <div class="mui-button-row">
		        <button type="button" class="mui-btn mui-btn-primary" id="login-btn">登录</button>
		    </div>
		</form>
		<a href="register.html" class="login-now">免费注册</a>
	</div>
</body>
<script>
    $(function(){
        $("#login-btn").on("click",function(){
            //获取用户登录的信息
            var username = $("#username").val();
            var password = $("#password").val();
            //判断用户名和密码
            if(username.trim() == ""){
                mui.toast("用户名不能为空");
            }
            $.ajax({
                type:"post",
                url:"/user/login",
                data:{
                    "username":username,
                    "password":password

                },
                beforeSend:function(){
                    $("#login-btn").html("正在登陆...");
                },
                success:function(res){
                    // console.log(res);
					if(res.success){
						mui.toast("登陆成功");
						$("#login-btn").html("登录...");
						setTimeout(() => {
							location.href = "user.html";
						}, 1000);
					}else{
						mui.toast(res.message);
					}
                    
                }
            });
        });
    })
</script>
</html>